﻿<template>
  <div class="maintenanceCountermeasureModels-container">
    <el-card shadow="hover" :body-style="{ paddingBottom: '0' }">
      <el-form :model="queryParams" ref="queryForm" labelWidth="90">
        <el-row>
          <el-col :xs="24" :sm="12" :md="12" :lg="8" :xl="4" class="mb10">
            <el-form-item label="关键字">
              <el-input v-model="queryParams.searchKey" clearable="" placeholder="请输入模糊查询关键字"/>
              
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12" :lg="8" :xl="4" class="mb10" v-if="showAdvanceQueryUI">
            <el-form-item label="pcl参数">
              <el-input v-model="queryParams.pcl" clearable="" placeholder="请输入pcl参数"/>
              
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12" :lg="8" :xl="4" class="mb10" v-if="showAdvanceQueryUI">
            <el-form-item label="RQI">
              <el-input v-model="queryParams.rqi" clearable="" placeholder="请输入RQI"/>
              
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12" :lg="8" :xl="4" class="mb10" v-if="showAdvanceQueryUI">
            <el-form-item label="RDI">
              <el-input v-model="queryParams.rdi" clearable="" placeholder="请输入RDI"/>
              
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12" :lg="8" :xl="4" class="mb10" v-if="showAdvanceQueryUI">
            <el-form-item label="SRI">
              <el-input v-model="queryParams.sri" clearable="" placeholder="请输入SRI"/>
              
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12" :lg="8" :xl="4" class="mb10" v-if="showAdvanceQueryUI">
            <el-form-item label="PBI">
              <el-input v-model="queryParams.pbi" clearable="" placeholder="请输入PBI"/>
              
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12" :lg="8" :xl="4" class="mb10" v-if="showAdvanceQueryUI">
            <el-form-item label="PSSI">
              <el-input v-model="queryParams.pssi" clearable="" placeholder="请输入PSSI"/>
              
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12" :lg="8" :xl="4" class="mb10" v-if="showAdvanceQueryUI">
            <el-form-item label="养护类型">
              <el-input v-model="queryParams.type"  clearable="" placeholder="请输入养护类型"/>
              
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12" :lg="8" :xl="4" class="mb10" v-if="showAdvanceQueryUI">
            <el-form-item label="说明">
              <el-input v-model="queryParams.reMark" clearable="" placeholder="请输入说明"/>
              
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12" :lg="6" :xl="6" class="mb10">
            <el-form-item>
              <el-button-group style="display: flex; align-items: center;">
                <el-button type="primary"  icon="ele-Search" @click="handleQuery" v-auth="'maintenanceCountermeasureModels:page'"> 查询 </el-button>
                <el-button icon="ele-Refresh" @click="() => queryParams = {}"> 重置 </el-button>
                <el-button icon="ele-ZoomIn" @click="changeAdvanceQueryUI" v-if="!showAdvanceQueryUI" style="margin-left:5px;"> 高级查询 </el-button>
                <el-button icon="ele-ZoomOut" @click="changeAdvanceQueryUI" v-if="showAdvanceQueryUI" style="margin-left:5px;"> 隐藏 </el-button>
                <el-button type="primary" style="margin-left:5px;" icon="ele-Plus" @click="openAddMaintenanceCountermeasureModels" v-auth="'maintenanceCountermeasureModels:add'"> 新增 </el-button>
                <el-button icon="ele-Edit" size="small" text type="primary" @click="openUploadDialog(11)" > 上传养护模型 </el-button>

              </el-button-group>
            </el-form-item>
            
          </el-col>
        </el-row>
      </el-form>
    </el-card>
    <el-card class="full-table" shadow="hover" style="margin-top: 5px">
      <el-table
				:data="tableData"
				style="width: 100%"
				v-loading="loading"
				tooltip-effect="light"
				row-key="id"
                @sort-change="sortChange"
				border="">
        <el-table-column type="index" label="序号" width="55" align="center"/>
        <el-table-column prop="pcl" label="pcl参数" width="140"  show-overflow-tooltip="" />
        <el-table-column prop="rqi" label="RQI" width="140"  show-overflow-tooltip="" />
        <el-table-column prop="rdi" label="RDI" width="140"  show-overflow-tooltip="" />
        <el-table-column prop="sri" label="SRI" width="140"  show-overflow-tooltip="" />
        <el-table-column prop="pbi" label="PBI" width="140"  show-overflow-tooltip="" />
        <el-table-column prop="pssi" label="PSSI" width="140"  show-overflow-tooltip="" />
        <el-table-column prop="type" label="养护方案序号" width="140"  show-overflow-tooltip="" />
        <el-table-column prop="reMark" label="养护类型" width="140"  show-overflow-tooltip="" />
        <el-table-column label="操作" width="140" align="center" fixed="right" show-overflow-tooltip="" v-if="auth('maintenanceCountermeasureModels:update') || auth('maintenanceCountermeasureModels:delete')">
          <template #default="scope">
            <el-button icon="ele-Edit" size="small" text="" type="primary" @click="openEditMaintenanceCountermeasureModels(scope.row)" v-auth="'maintenanceCountermeasureModels:update'"> 编辑 </el-button>
            <el-button icon="ele-Delete" size="small" text="" type="primary" @click="delMaintenanceCountermeasureModels(scope.row)" v-auth="'maintenanceCountermeasureModels:delete'"> 删除 </el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
				v-model:currentPage="tableParams.page"
				v-model:page-size="tableParams.pageSize"
				:total="tableParams.total"
				:page-sizes="[10, 20, 50, 100, 200, 500]"
				small=""
				background=""
				@size-change="handleSizeChange"
				@current-change="handleCurrentChange"
				layout="total, sizes, prev, pager, next, jumper"
	/>
      <printDialog
        ref="printDialogRef"
        :title="printMaintenanceCountermeasureModelsTitle"
        @reloadTable="handleQuery" />
      <editDialog
        ref="editDialogRef"
        :title="editMaintenanceCountermeasureModelsTitle"
        @reloadTable="handleQuery"
      />
    </el-card>
    <el-dialog v-model="state.dialogUploadVisible" :lock-scroll="false" draggable width="400px">
      <template #header>
        <div style="color: #fff">
          <el-icon size="16" style="margin-right: 3px; display: inline; vertical-align: middle"> <ele-UploadFilled /> </el-icon>
          <span> 上传文件 </span>
        </div>
      </template>
      <div>
        <el-upload ref="uploadRef" drag :auto-upload="false" :limit="1" :file-list="state.fileList" action="" :on-change="handleChange" accept=".jpg,.png,.bmp,.gif,.txt,.pdf,.xlsx,.docx">
          <el-icon class="el-icon--upload">
            <ele-UploadFilled />
          </el-icon>
          <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
          <template #tip>
            <div class="el-upload__tip">请上传大小不超过 10MB 的文件</div>
          </template>
        </el-upload>
      </div>
      <template #footer>
				<span class="dialog-footer">
					<el-button @click="state.dialogUploadVisible = false">取消</el-button>
					<el-button type="primary" @click="uploadFile">确定</el-button>
				</span>
      </template>
    </el-dialog>
  </div>
</template>

<script lang="ts" setup="" name="maintenanceCountermeasureModels">
  import {reactive, ref} from "vue";
  import { ElMessageBox, ElMessage } from "element-plus";
  import { auth } from '/@/utils/authFunction';
  import { getDictDataItem as di, getDictDataList as dl } from '/@/utils/dict-utils';
  import { formatDate } from '/@/utils/formatTime';


  import printDialog from '/@/views/system/print/component/hiprint/preview.vue'
  import editDialog from '/@/views/main/maintenanceCountermeasureModels/component/editDialog.vue'
  import { pageMaintenanceCountermeasureModels, deleteMaintenanceCountermeasureModels } from '/@/api/main/maintenanceCountermeasureModels';
  import {uploadFilesPoject} from "/@/api/region/region";

  import {SysFile, SysRegion} from '/@/api-services/models';

  const showAdvanceQueryUI = ref(false);
  const printDialogRef = ref();
  const editDialogRef = ref();
  const loading = ref(false);
  const tableData = ref<any>([]);
  const queryParams = ref<any>({});
  const tableParams = ref({
    page: 1,
    pageSize: 10,
    total: 0,
  });
  const state = reactive({
    loading: false,
    key:0,
    Pid : undefined,
    fileData: [] as Array<SysFile>,
    fileList: [] as any,
    fileName: '',
    regionData: [] as Array<SysRegion>, // 列表数据
    queryParams: {
      id: -1,
      pid: undefined,
      roadNo: undefined,
      roadname: undefined,
    },
    tableParams: {
      page: 1,
      pageSize: 20,
      total: 0 as any,
    },
    editRegionTitle: '',
  });

  const printMaintenanceCountermeasureModelsTitle = ref("");
  const editMaintenanceCountermeasureModelsTitle = ref("");

  // 改变高级查询的控件显示状态
  const changeAdvanceQueryUI = () => {
    showAdvanceQueryUI.value = !showAdvanceQueryUI.value;
  }

  // 通过onChanne方法获得文件列表
  const handleChange = (file: any, fileList: []) => {
    state.fileList = fileList;
    console.log('实例',state)
  };

  // 取消
  const cancel = () => {
    state.fileList = [];
    state.isShowDialog = false;
  };

  // 打开上传页面
  const openUploadDialog = (key:any) => {
    state.fileList = [];
    state.Pid="1";
    state.key=key;
    state.dialogUploadVisible = true;
  };

  // 上传
  const uploadFile = async () => {
    const params = new FormData();

    if (state.fileList.length >=1){
      for (let i = 0; i < state.fileList.length; i++) {
        state.fileList[i].pid = state.Pid;
        params.append('files', state.fileList[i].raw);
      }
      params.append('pid',state.Pid);
      params.append('key',state.key);
      await uploadFilesPoject(params);
    }
    handleQuery();
    state.key=0;
    state.Pid=0;
    state.dialogUploadVisible = false;
  };


  // 查询操作
  const handleQuery = async () => {
    loading.value = true;
    var res = await pageMaintenanceCountermeasureModels(Object.assign(queryParams.value, tableParams.value));
    tableData.value = res.data.result?.items ?? [];
    tableParams.value.total = res.data.result?.total;
    loading.value = false;
  };

  // 列排序
  const sortChange = async (column: any) => {
	queryParams.value.field = column.prop;
	queryParams.value.order = column.order;
	await handleQuery();
  };

  // 打开新增页面
  const openAddMaintenanceCountermeasureModels = () => {
    editMaintenanceCountermeasureModelsTitle.value = '添加养护模型';
    editDialogRef.value.openDialog({});
  };

  // 打开打印页面
  const openPrintMaintenanceCountermeasureModels = async (row: any) => {
    printMaintenanceCountermeasureModelsTitle.value = '打印养护模型';
  }
  
  // 打开编辑页面
  const openEditMaintenanceCountermeasureModels = (row: any) => {
    editMaintenanceCountermeasureModelsTitle.value = '编辑养护模型';
    editDialogRef.value.openDialog(row);
  };

  // 删除
  const delMaintenanceCountermeasureModels = (row: any) => {
    ElMessageBox.confirm(`确定要删除吗?`, "提示", {
    confirmButtonText: "确定",
    cancelButtonText: "取消",
    type: "warning",
  })
  .then(async () => {
    await deleteMaintenanceCountermeasureModels(row);
    handleQuery();
    ElMessage.success("删除成功");
  })
  .catch(() => {});
  };

  // 改变页面容量
  const handleSizeChange = (val: number) => {
    tableParams.value.pageSize = val;
    handleQuery();
  };

  // 改变页码序号
  const handleCurrentChange = (val: number) => {
    tableParams.value.page = val;
    handleQuery();
  };

  handleQuery();
</script>
<style scoped>
:deep(.el-ipnut),
:deep(.el-select),
:deep(.el-input-number) {
	width: 100%;
}
</style>

